package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.bean.HomePageBean;
import com.atwork.wuhua.bean.LaunchBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.ILaunchFragment;
import com.atwork.wuhua.utils.LogUtils;
import com.atwork.wuhua.utils.SPUtils;

public class LaunchPresenter extends BasePresenter<ILaunchFragment> {
    private double lat = 0;
    private double log = 0;

    public void getData(int page) {
        if (lat == 0 || log == 0) {
            if (!SPUtils.getString(getView().getContext(), SPUtils.LATITUDE).equals("") & !SPUtils.getString(getView().getContext(), SPUtils.LONGITUDE).equals("")) {
                lat = Double.parseDouble(SPUtils.getString(getView().getContext(), SPUtils.LATITUDE));
                log = Double.parseDouble(SPUtils.getString(getView().getContext(), SPUtils.LONGITUDE));
            }
        }
        BaseReq req = new BaseReq();
        req.setKey("page", page + "");
        req.setKey("page_size", "10");
        req.setKey("position", log + "," + lat);
        LogUtils.e("约战==>" + req.getString());
        DataModel.request(Token.API_LAYNCH_LISTS)
                .params(req)
                .execute(new Callback<LaunchBean>() {

                    public void onSuccess(String msg, LaunchBean data) {
                        hideLoading();
                        getView().setData(data);
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                        getView().noData();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
